# -*- coding:utf-8 -*-
from __future__ import absolute_import, unicode_literals
import os
from celery import Celery
from celery.schedules import crontab
from ElevatorAdmin.settings import redis_host, TO_GOV, redis_password

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ElevatorAdmin.settings')
# app = Celery('ElevatorAdmin', broker='redis://' + redis_host + ':6379/9')
if TO_GOV:
    app = Celery('ElevatorAdmin', broker='redis://' + redis_host + ':6379/9')
else:
    app = Celery('ElevatorAdmin', broker='redis://' + ":" + redis_password + "@" + redis_host + ':6379/9')
app.config_from_object('django.conf:settings', namespace='CELERY')
# app.config_from_object('ElevatorAdmin.celeryconfig')
# app.autodiscover_tasks(lambda: settings.INSTALLED_APP)
app.autodiscover_tasks()

app.conf.beat_schedule = {

    'auto_add_periodic_task': {

        'task': 'ElevatorAdmin.tasks.auto_add_periodic_task',

        'schedule': crontab(hour=7, minute=30),

    },

    'auto_add_elevator_statistics': {

        'task': 'ElevatorAdmin.tasks.auto_add_elevator_statistics',

        'schedule': crontab(hour=7, minute=30),
    },

    'do_beat_for_register': {
        'task': 'ElevatorAdmin.tasks.do_beat_for_register',
        'schedule': 30
    },

    'cal_elevator_number_for_every_year': {
        'task': 'ElevatorAdmin.tasks.cal_elevator_number_for_every_year',
        'schedule': 300
    },

    'statistics_for_register': {

        'task': 'ElevatorAdmin.tasks.statistics_for_register',

        'schedule': crontab(hour=22),
    },

    'statistics_for_authority': {

        'task': 'ElevatorAdmin.tasks.statistics_for_authority_code_update',

        'schedule': crontab(minute=0, hour=0),
    },

}